/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.compiere.apps.form;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.compiere.apps.StatusBar;
import org.compiere.grid.ed.VDate;
import org.compiere.grid.ed.VLookup;
import org.compiere.minigrid.MiniTable;
import org.compiere.swing.CPanel;
import org.compiere.swing.CTextField;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.CLogger;

/**
 * 
 * @author alm
 */
public class PlanFact implements FormPanel {

	/**
	 * Creates new form NewJFrame
	 */
	// Properties ctx;

	int ad_table_id = 0;
	int record_id = 0;
	public static CLogger log = CLogger.getCLogger(PlanFact.class);

	// public PlanFact() {
	// // this.ctx = ctx;
	//
	// // time
	//
	// initComponents();
	//
	// initComponents();
	// // setConnect();
	// loadC_Charge_id();
	// // loadTables();
	//
	// // make the frame half the height and width
	// // Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
	// // int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
	// // int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
	// // this.setLocation(x, y);
	//
	//
	//
	// }

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {
		jSplitPane1 = new javax.swing.JSplitPane();
		jScrollPane4 = new javax.swing.JScrollPane();
		jPanel3 = new javax.swing.JPanel();
		jToolBar3 = new javax.swing.JToolBar();
		jbSelectAll = new javax.swing.JButton();
		jcbC_charge_id = new javax.swing.JComboBox();
		jbSetAll = new javax.swing.JButton();
		jScrollPane6 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();
		jSplitPane2 = new javax.swing.JSplitPane();
		jScrollPane2 = new javax.swing.JScrollPane();
		jPanel1 = new javax.swing.JPanel();
		jToolBar1 = new javax.swing.JToolBar();
		jScrollPane5 = new javax.swing.JScrollPane();
		jList2 = new javax.swing.JList();
		jScrollPane3 = new javax.swing.JScrollPane();
		jSplitPane3 = new javax.swing.JSplitPane();
		jScrollPane1 = new javax.swing.JScrollPane();
		jPanel2 = new javax.swing.JPanel();
		jToolBar2 = new javax.swing.JToolBar();
		jButton1 = new javax.swing.JButton();
		jScrollPane7 = new javax.swing.JScrollPane();
		jList1 = new javax.swing.JList();
		jScrollPane8 = new javax.swing.JScrollPane();
		jTable2 = new javax.swing.JTable();

		// setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		// setBackground(java.awt.Color.lightGray);

		jSplitPane1.setBackground(java.awt.Color.lightGray);
		jSplitPane1.setDividerLocation(500);

		jToolBar3.setFloatable(false);
		jToolBar3.setRollover(true);

		jbSelectAll.setText("check all");
		jbSelectAll.setFocusable(false);
		jbSelectAll
				.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbSelectAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbSelectAll.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jbSelectAllActionPerformed(evt);
			}
		});
		jToolBar3.add(jbSelectAll);

		jcbC_charge_id.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
		jcbC_charge_id.setPreferredSize(new java.awt.Dimension(300, 24));
		jToolBar3.add(jcbC_charge_id);

		jbSetAll.setText("set all");
		jbSetAll.setFocusable(false);
		jbSetAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbSetAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbSetAll.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jbSetAllActionPerformed(evt);
			}
		});
		jToolBar3.add(jbSetAll);

		jTable1.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { {}, {}, {}, {} }, new String[] {

				}));
		jScrollPane6.setViewportView(jTable1);

		javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(
				jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout.setHorizontalGroup(jPanel3Layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane6,
						javax.swing.GroupLayout.DEFAULT_SIZE, 679,
						Short.MAX_VALUE)
				.addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
		jPanel3Layout
				.setVerticalGroup(jPanel3Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel3Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar3,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												25,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane6,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												509, Short.MAX_VALUE)));

		jScrollPane4.setViewportView(jPanel3);

		jSplitPane1.setRightComponent(jScrollPane4);

		jSplitPane2.setDividerLocation(150);
		jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

		jToolBar1.setRollover(true);

		jList2.setModel(new javax.swing.AbstractListModel() {
			String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4",
					"Item 5" };

			public int getSize() {
				return strings.length;
			}

			public Object getElementAt(int i) {
				return strings[i];
			}
		});
		jScrollPane5.setViewportView(jList2);

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(jScrollPane5,
						javax.swing.GroupLayout.PREFERRED_SIZE, 0,
						Short.MAX_VALUE));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												25,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(
												jScrollPane5,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												115,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap()));

		jScrollPane2.setViewportView(jPanel1);

		jSplitPane2.setTopComponent(jScrollPane2);
		jSplitPane2.setRightComponent(jScrollPane3);

		jSplitPane1.setLeftComponent(jSplitPane2);

		jSplitPane3.setDividerLocation(300);
		jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

		jToolBar2.setFloatable(false);
		jToolBar2.setRollover(true);

		jButton1.setText("load");
		jButton1.setFocusable(false);
		jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});
		jToolBar2.add(jButton1);

		jList1.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jList1MouseClicked(evt);
			}
		});
		jScrollPane7.setViewportView(jList1);

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(jPanel2Layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(jScrollPane7,
						javax.swing.GroupLayout.DEFAULT_SIZE, 498,
						Short.MAX_VALUE));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												25,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane7,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												267, Short.MAX_VALUE)));

		jScrollPane1.setViewportView(jPanel2);

		jSplitPane3.setTopComponent(jScrollPane1);

		jTable2.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { {}, {}, {}, {} }, new String[] {

				}));
		jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jTable2MouseClicked(evt);
			}
		});
		jScrollPane8.setViewportView(jTable2);

		jSplitPane3.setRightComponent(jScrollPane8);

		jSplitPane1.setLeftComponent(jSplitPane3);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(mainPanel);
		mainPanel.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING,
				javax.swing.GroupLayout.DEFAULT_SIZE, 987, Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING,
				javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE));

		// mainPanel.pack();

	}// </editor-fold>

	protected void loadC_Charge_id() {
		// try {
		// Statement st = null;
		// ResultSet rs = null;
		// st = connection.createStatement();
		String sql = "   select c_charge_id, name from adempiere.c_charge order by c_charge_id";
		//
		// rs = st.executeQuery(sql);
		//
		jcbC_charge_id.removeAllItems();
		//
		// while(rs.next()){
		// jcbC_charge_id.addItem(rs.getString(2) + "-" +rs.getString(1));
		// }
		//
		// } catch (Exception ex) {
		// Logger lgr = Logger.getLogger(Connection.class.getName());
		// lgr.log(Level.SEVERE, ex.getMessage(), ex);
		//
		// }

		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String Description = null;
		try {
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();
			while (rs.next())
				jcbC_charge_id.addItem(rs.getString(2) + "-" + rs.getString(1));
		} catch (SQLException ee) {
			log.log(Level.SEVERE, sql, ee);
		} finally {
			DB.close(rs, pstmt);
			rs = null;
			pstmt = null;
		}

	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		loadTables();
	}

	private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
//		int index = jList1.locationToIndex(evt.getPoint());
//		DefaultListModel<String> model = (DefaultListModel<String>) jList1
//				.getModel();
//		String TableName = model.get(index);
//
//		// System.out.println(index+",     "+ TableName);
//		int id = Integer
//				.parseInt(TableName.substring(0, TableName.indexOf("=")));
//		ad_table_id = id;
//
//		TableName = TableName.substring(TableName.indexOf("=") + 1,
//				TableName.length());
//		loadLines(TableName);
	}

	private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {
		int row = jTable2.rowAtPoint(evt.getPoint());
		DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
		String s = model.getValueAt(row, 0).toString();
		record_id = Integer.parseInt(s);
		loadFactss(ad_table_id, record_id);

	}

	private void jbSelectAllActionPerformed(java.awt.event.ActionEvent evt) {
		jTable1.selectAll();
	}

	private void jbSetAllActionPerformed(java.awt.event.ActionEvent evt) {

		int selRows[] = jTable1.getSelectedRows();
		String c_charge = (String) jcbC_charge_id.getSelectedItem();
		int c_charge_id = Integer.parseInt(c_charge.substring(
				c_charge.indexOf("-") + 1, c_charge.length()));

		List<Integer> list = new ArrayList<Integer>();
		DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
		for (int i = 0; i < selRows.length; i++) {
			String value = (String) model.getValueAt(selRows[i], 1);
			// System.out.println(value);
			int fact_acct_id = Integer.parseInt(value);
			setFactAcctC_Charge_id(fact_acct_id, c_charge_id);
		}

		loadFactss(ad_table_id, record_id);

	}

	protected void setFactAcctC_Charge_id(int factacct_id, int c_charge_id) {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = "   update adempiere.fact_acct set c_charge_id = "
				+ c_charge_id + "   where fact_acct_id = " + factacct_id;

		try {
			// Statement st = null;
			// ResultSet rs = null;
			// st = connection.createStatement();

			// st.executeQuery(sql);
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();

			// } catch (Exception ex) {
			// Logger lgr = Logger.getLogger(Connection.class.getName());
			// lgr.log(Level.SEVERE, ex.getMessage(), ex);
			//
			// }
		} catch (SQLException ee) {
//			log.log(Level.SEVERE, sql, ee);
		} finally {
			DB.close(rs, pstmt);
			rs = null;
			pstmt = null;
		}

	}

	protected void loadFactss(int ad_table_id, int record_id) {

		PreparedStatement pstmt = null;
		ResultSet rs = null;

		String sql = "   select c_charge_id, * from adempiere.fact_acct   "
				+ "   where ad_table_id = " + ad_table_id
				+ "   and record_id = " + record_id;

		try {
			// Statement st = null;
			// ResultSet rs = null;
			// st = connection.createStatement();

			// rs = st.executeQuery(sql);
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();

			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();

			int c = 0;
			while (rs.next())
				c++;
			int rowCount = c;

			String colNames[] = new String[columnCount];
			for (int i = 1; i <= columnCount; i++) {
				if (i == 1)
					colNames[i - 1] = "check";
				colNames[i - 1] = rsmd.getColumnName(i);
			}

			String rows[] = new String[rowCount];

			DefaultTableModel dataModel = new DefaultTableModel();// new
																	// Object[rows.length,
																	// colNames.length])
																	// {
			for (int i = 0; i < columnCount; i++)
				dataModel.addColumn(colNames[i]);

			jTable1.setModel(dataModel);

			String rowData[] = new String[columnCount];
			pstmt = null;
			rs = null;
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();
			int i = 0;
			while (rs.next()) {
				for (int j = 1; j <= columnCount; j++) {

					if (rs.getObject(j) != null)
						rowData[j - 1] = rs.getObject(j).toString();
				}
				dataModel.insertRow(i++, rowData);
				for (int k = 0; k < columnCount; k++)
					rowData[k] = "";
			}
			jTable1.setAutoResizeMode(jTable2.AUTO_RESIZE_OFF);

		} catch (Exception ex) {
			Logger lgr = Logger.getLogger(Connection.class.getName());
			lgr.log(Level.SEVERE, ex.getMessage(), ex);

		}

	}

	protected void loadLines(String tableName) {

		PreparedStatement pstmt = null;
		ResultSet rs = null;

		String sql = "select " + tableName + "_id, *   from adempiere."
				+ tableName;
		;

		try {
			// Statement st = null;
			// ResultSet rs = null;
			// st = connection.createStatement();

			// rs = st.executeQuery(sql);
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();

			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();

			int c = 0;
			while (rs.next())
				c++;
			int rowCount = c;

			String colNames[] = new String[columnCount];
			for (int i = 1; i <= columnCount; i++)
				colNames[i - 1] = rsmd.getColumnName(i);

			String rows[] = new String[rowCount];

			DefaultTableModel dataModel = new DefaultTableModel();// new
																	// Object[rows.length,
																	// colNames.length])
																	// {
			for (int i = 0; i < columnCount; i++)
				dataModel.addColumn(colNames[i]);

			jTable2.setModel(dataModel);

			String rowData[] = new String[columnCount];
			// rs = st.executeQuery(sql);
			pstmt = null;
			rs = null;
			pstmt = DB.prepareStatement(sql, null);
			rs = pstmt.executeQuery();
			int i = 0;
			while (rs.next()) {
				for (int j = 1; j <= columnCount; j++) {

					if (rs.getObject(j) != null)
						rowData[j - 1] = rs.getObject(j).toString();
				}
				dataModel.insertRow(i++, rowData);
				for (int k = 0; k < columnCount; k++)
					rowData[k] = "";
			}
			jTable2.setAutoResizeMode(jTable2.AUTO_RESIZE_OFF);

			// } catch (Exception ex) {
			// Logger lgr = Logger.getLogger(Connection.class.getName());
			// lgr.log(Level.SEVERE, ex.getMessage(), ex);
			//
			// }
		} catch (SQLException ee) {
			log.log(Level.SEVERE, sql, ee);
		} finally {
			DB.close(rs, pstmt);
			rs = null;
			pstmt = null;
		}

	}

	protected void loadTables() {

//		DefaultListModel<String> model = new DefaultListModel<String>();
//
//		// try {
//		// //con = DriverManager.getConnection(url, user, password);
//		// Statement st = null;
//		// ResultSet rs = null;
//		// st = connection.createStatement();
//		String sql = "with tabless as (\n"
//				+ "select \n"
//				+ "t.ad_table_id, t.name, t.tablename\n"
//				+ "from adempiere.ad_table t\n"
//				+ "inner join adempiere.ad_column c on c.ad_table_id = t.ad_table_id\n"
//				+ "inner join adempiere.ad_element e on c.ad_element_id = e.ad_element_id\n"
//				+ "where upper(e.columnname) = upper('c_charge_id')\n"
//				+ "order by t.ad_table_id\n" + ") \n"
//				+ "select  ad_table_id, name, tablename  from tabless;";
//
//		// rs = st.executeQuery(sql);
//
//		// int i=0;
//		// while (rs.next()) {
//		// listline line = new listline(rs.getInt(1), rs.getString(3));
//		// model.add(i++,(rs.getString(1)+"="+ rs.getString(3)));
//		// }
//
//		// jList1.setModel(model);
//
//		// } catch (SQLException ex) {
//		// Logger lgr = Logger.getLogger(Connection.class.getName());
//		// lgr.log(Level.SEVERE, ex.getMessage(), ex);
//		//
//		// }
//
//		PreparedStatement pstmt = null;
//		ResultSet rs = null;
//		String Description = null;
//		try {
//			pstmt = DB.prepareStatement(sql, null);
//			rs = pstmt.executeQuery();
//			int i = 0;
//			while (rs.next())
//				model.add(i++, (rs.getString(1) + "=" + rs.getString(3)));
//
//			jList1.setModel(model);
//		} catch (SQLException ee) {
//			log.log(Level.SEVERE, sql, ee);
//		} finally {
//			DB.close(rs, pstmt);
//			rs = null;
//			pstmt = null;
//		}

	}

	// protected void setConnect(){
	// System.out.println("-------- PostgreSQL "
	// + "JDBC Connection Testing ------------");
	//
	// try {
	//
	// Class.forName("org.postgresql.Driver");
	//
	// } catch (ClassNotFoundException e) {
	//
	// System.out.println("Where is your PostgreSQL JDBC Driver? "
	// + "Include in your library path!");
	// e.printStackTrace();
	// return;
	//
	// }
	// System.out.println("PostgreSQL JDBC Driver Registered!");
	//
	// try {
	//
	// connection = DriverManager.getConnection(
	// "jdbc:postgresql://localhost:5432/18092013", "postgres",
	// "IEi3HGJBDg+2154Z");
	// // "jdbc:postgresql://192.168.125.222:5432/adempiere", "adempiere",
	// "adempiere");
	// try {
	// //con = DriverManager.getConnection(url, user, password);
	// Statement st = null;
	// ResultSet rs = null;
	// st = connection.createStatement();
	// rs = st.executeQuery("SELECT 1 limit 1");
	//
	// if (rs.next()) {
	// System.out.println(rs.getString(1));
	// }
	//
	// } catch (SQLException ex) {
	// Logger lgr = Logger.getLogger(Connection.class.getName());
	// lgr.log(Level.SEVERE, ex.getMessage(), ex);
	//
	// }
	//
	// } catch (SQLException e) {
	//
	// System.out.println("Connection Failed! Check output console");
	// e.printStackTrace();
	// return;
	//
	// }
	//
	// if (connection != null) {
	// System.out.println("You made it, take control your database now!");
	// } else {
	// System.out.println("Failed to make connection!");
	// }

	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JList jList1;
	private javax.swing.JList jList2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JScrollPane jScrollPane4;
	private javax.swing.JScrollPane jScrollPane5;
	private javax.swing.JScrollPane jScrollPane6;
	private javax.swing.JScrollPane jScrollPane7;
	private javax.swing.JScrollPane jScrollPane8;
	private javax.swing.JSplitPane jSplitPane1;
	private javax.swing.JSplitPane jSplitPane2;
	private javax.swing.JSplitPane jSplitPane3;
	private javax.swing.JTable jTable1;
	private javax.swing.JTable jTable2;
	private javax.swing.JToolBar jToolBar1;
	private javax.swing.JToolBar jToolBar2;
	private javax.swing.JToolBar jToolBar3;
	private javax.swing.JButton jbSelectAll;
	private javax.swing.JButton jbSetAll;
	private javax.swing.JComboBox jcbC_charge_id;
	// End of variables declaration
	Connection connection = null;

	@Override
	public void init(int WindowNo, FormFrame frame) {
		// this.ctx = ctx;

		// time

		// initComponents();

		// initComponents();
		// setConnect();
		// loadC_Charge_id();
		// loadTables();

		// make the frame half the height and width
		// Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
		// int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
		// int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
		// this.setLocation(x, y);
		m_WindowNo = WindowNo;
		m_frame = frame;
		Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y"); // defaults to
																	// no
		try {
			// dynInit();
			// jbInit();
			// calculate();
			initComponents();
			// setConnect();
			loadC_Charge_id();
			loadTables();

			frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
			frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
		} catch (Exception e) {
			log.log(Level.SEVERE, "", e);
		}

	}

	/** Window No */
	private int m_WindowNo = 0;
	/** FormFrame */
	private FormFrame m_frame;

	private CPanel mainPanel = new CPanel();
	private BorderLayout mainLayout = new BorderLayout();
	private CPanel parameterPanel = new CPanel();
	private CPanel transferPanel = new CPanel();
	private GridBagLayout parameterLayout = new GridBagLayout();
	private JLabel bpartnerLabel = new JLabel();
	private VLookup bpartnerSearch = null;
	private JLabel bpartner2Label = new JLabel();
	private VLookup bpartner2Search = null;
	private MiniTable assetTable = new MiniTable();
	private CPanel assetPanel = new CPanel();
	private JLabel assetLabel = new JLabel();
	private BorderLayout assetLayout = new BorderLayout();
	private JLabel assetInfo = new JLabel();
	private JScrollPane assetScrollPane = new JScrollPane();
	private GridBagLayout transferLayout = new GridBagLayout();
	private JLabel differenceLabel = new JLabel();
	private CTextField differenceField = new CTextField();
	private JButton transferButton = new JButton();
	private StatusBar statusBar = new StatusBar();
	private JLabel dateLabel = new JLabel();
	private VDate dateField = new VDate();
	private JLabel organizationLabel = new JLabel();
	private VLookup organizationPick = null;
	private JLabel descriptionLabel = new JLabel();
	private CTextField descriptionField = new CTextField();

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
